package cartes;

public class Carte implements Comparable<Carte> {
	private CouleurCarte couleur = null;
	private Denomination denomination = null;
	
	public Carte(Denomination d, CouleurCarte c){
		this.couleur = c;
		this.denomination = d;
	}

	public CouleurCarte getCouleur() {
		return couleur;
	}
	
	public Denomination getDenomination() {
		return denomination;
	}
  
	public int getIndexDenomination(){
	  return Denomination.DENOMINATIONS.indexOf(denomination);
	}
	
	public int compareTo(Carte o) {
		if (o == null)
			throw new NullPointerException();
		
		int tempCompare = denomination.compareTo(o.getDenomination());
		if (tempCompare != 0)
			return tempCompare;
		else	
			return  couleur.compareTo(o.getCouleur());
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Carte other = (Carte) obj;
		
		if (denomination == null) {
			if (other.denomination != null)
				return false;
		} else if (!denomination.equals(other.denomination))
			return false;
		return true;
	}
	
	public boolean estValide() {
		if (!this.denomination.estValide() || !this.couleur.estValide())
			return false;
		return true;
	}
	
	public String toString() {
		return denomination.toString() + " de " + couleur.toString();		
	}
	
	//test
	public static void main(String[] args){
		Carte c1,c2;
		
		c1 = new Carte(Denomination.AS,CouleurCarte.CARREAU);
		c2 = new Carte(Denomination.CINQ, CouleurCarte.COEUR);
	}

}

